package com.iengine.services.api.command.chat;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.iengine.services.api.utils.DateUtils;

public class CommandDate extends AbstractTxtPhoneApiCommand{
	
	private static final String FIELD_DATE= "Date";
	
	private static Calendar calendar = Calendar.getInstance();
	private static Map<Integer, String> dayOfWeekMap = new HashMap<Integer, String>();
	static{
		dayOfWeekMap.put(1, "日");
		dayOfWeekMap.put(2, "一");
		dayOfWeekMap.put(3, "二");
		dayOfWeekMap.put(4, "三");
		dayOfWeekMap.put(5, "四");
		dayOfWeekMap.put(6, "五");
		dayOfWeekMap.put(7, "六");
	}
	@Override
	protected Map formatArgs(Map map,Map nlpParams) {
		String date = getValue(nlpParams.get(FIELD_DATE), null);
		Date searchDate = null;
		if (StringUtils.isNotBlank(date)) {
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_MONTH, Integer.parseInt(date) - 2);
			searchDate = calendar.getTime();
		} else {
			searchDate = new Date();
		}
		String dateStr = DateUtils.convert(searchDate, DateUtils.DATE_CH_FORMAT);
		dateStr=dateStr+"星期"+dayOfWeekMap.get(calendar.get(Calendar.DAY_OF_WEEK));
		map = addValue(map, isDirectReturn(), dateStr);
		return map;
	}

}
